package com.briup.pts.service.impl;

import com.briup.pts.domain.bean.Log;
import com.briup.pts.mapper.LogMapper;
import com.briup.pts.service.LogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class LogServiceImpl implements LogService {

    private final LogMapper logMapper;

    @Override
    public void addLog(Log log) {
        logMapper.addLog(log);
    }

    @Override
    public PageInfo<Log> pageQuery(Integer pageNum, Integer pageSize, String originalIp) {
        try (Page<Log> ignored = PageHelper.startPage(pageNum,pageSize)){
            List<Log> logs = logMapper.queryByConditional(originalIp);
            Page<Log> logPage = (Page<Log>) logs;
            return new PageInfo<>(logPage);
        }
    }
}

